package cn.bluethink.eguan.core.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;

import cn.bluethink.eguan.model.core.EgCheckStatus;
import cn.bluethink.eguan.model.core.EgOType;
import cn.bluethink.eguan.model.core.EgObject;
import cn.bluethink.eguan.model.core.EgProirity;
import cn.bluethink.eguan.model.core.EgTask;
import cn.bluethink.eguan.model.core.EgTaskStatus;
import cn.bluethink.eguan.model.core.EgUser;

/**
 * 通用任务实体类
 * 
 * @title 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1.0
 * @describe
 * @author liuxn
 * @date 2018年10月13日
 */
@Table(name = "eg_task")
public class EgTaskEntity implements Serializable {
    private static final long serialVersionUID = -3734652275525639623L;

    @Id
    private Long tid;

    private Integer otype;

    private String name;

    private String content;

    private String tags;

    private Integer status;

    private Integer priority;

    private Integer cycle;

    @Column(name = "pos_otype")
    private Integer posOtype;

    @Column(name = "pos_oid")
    private Long posOid;

    @Column(name = "result_type")
    private Integer resultType;

    private Long cuid;

    private Date btime;

    private Date etime;

    private Date ctime;

    private Date utime;

    private Date ftime;

	@Column(name = "check_status")
    private Integer checkStatus;
	
	@Column(name="del_flag")
	private Integer delFlag;

    public EgTaskEntity() {

    }

    /**
     * 创建/编辑任务
     * 
     * @param task
     * @param bcreate
     */
    public EgTaskEntity(EgTask task, boolean bcreate) {
        this.tid = task.getId();
        this.otype = task.getType().getOtid();
        this.name = task.getName();
        this.content = task.getContent();
        this.tags = task.getTags();
        this.posOid = task.getPos() == null ? null : task.getPos().getId();
        this.posOtype = task.getPos() == null ? null : task.getPos().getType().getOtid();
        this.resultType = task.getRtype() == null ? null : task.getRtype().getOtid();
        this.cuid = task.getCuser() == null ? null : task.getCuser().getId();
        this.btime = task.getBtime();
        this.etime = task.getEtime();
        this.ftime = task.getFtime();
        if (bcreate) {
            this.status = task.getStatus() == null ? EgTaskStatus.STATUS_NEW : task.getStatus();
            this.priority = task.getPriority() == null ? EgProirity.PRIORITY_LOW : task.getPriority();
            this.checkStatus = task.getCheckStatus() == null ? EgCheckStatus.STATUS_PENDING : task.getCheckStatus();
        } else {
            this.status = task.getStatus();
            this.priority = task.getPriority();
            this.checkStatus = task.getCheckStatus();
        }
    }

    /**
     * 实体 转换为 模型
     * 
     * @return
     */
    public EgTask createEgTask() {
        EgTask task = new EgTask();
        task.setId(tid);
        // 设置任务的类型
        task.setType(new EgOType(otype, null));
        task.setName(name);
        task.setContent(content);
        task.setTags(tags);
        if(status == null) {
        	status = EgTaskStatus.STATUS_NEW;
        }
        task.setStatus(status);
        task.setPriority(priority);
        EgObject pos = new EgObject();
        pos.setId(posOid);
        pos.setType(new EgOType(posOtype, null));
        task.setPos(pos);
        // 设置任务结果的类型
        if (resultType != null && resultType > 0) {
            task.setRtype(new EgOType(resultType, null));
        } else {
            task.setRtype(null);
        }
        task.setCuser(new EgUser(cuid, null, null));
        task.setBtime(btime);
        task.setEtime(etime);
        task.setUtime(ctime);
        task.setFtime(ftime);
        task.setCheckStatus(checkStatus);
        return task;
    }

    public Long getTid() {
        return tid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public Integer getOtype() {
        return otype;
    }

    public void setOtype(Integer otype) {
        this.otype = otype;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Integer getCycle() {
        return cycle;
    }

    public void setCycle(Integer cycle) {
        this.cycle = cycle;
    }

    public Integer getPosOtype() {
        return posOtype;
    }

    public void setPosOtype(Integer posOtype) {
        this.posOtype = posOtype;
    }

    public Long getPosOid() {
        return posOid;
    }

    public void setPosOid(Long posOid) {
        this.posOid = posOid;
    }

    public Date getBtime() {
        return btime;
    }

    public void setBtime(Date btime) {
        this.btime = btime;
    }

    public Integer getResultType() {
        return resultType;
    }

    public void setResultType(Integer resultType) {
        this.resultType = resultType;
    }

    public Long getCuid() {
        return cuid;
    }

    public void setCuid(Long cuid) {
        this.cuid = cuid;
    }

    public Date getEtime() {
        return etime;
    }

    public void setEtime(Date etime) {
        this.etime = etime;
    }

    public Date getCtime() {
        return ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }

    public Date getUtime() {
        return utime;
    }

    public void setUtime(Date utime) {
        this.utime = utime;
    }

    public Date getFtime() {
        return ftime;
    }

    public void setFtime(Date ftime) {
        this.ftime = ftime;
    }

    public Integer getCheckStatus() {
        return checkStatus;
    }

    public void setCheckStatus(Integer checkStatus) {
        this.checkStatus = checkStatus;
    }

	public Integer getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(Integer delFlag) {
		this.delFlag = delFlag;
	}
    

}
